package com.igeek.javase.ch02;

import java.util.Scanner;

/*
 *@author wangpeng
 *2023/7/11 18:09
 *@description GuessNumber
 */
public class ForTest1 {
    public static void main(String[] args) {
        System.out.println("Java实现猜数字游戏(请在0~100之间猜数据):");
        int data = (int) (Math.random() * 100 + 1);//产生随机数
        Scanner guessnum = new Scanner(System.in);
        for (int i = 1; i <= 7; i++) {
            int num = guessnum.nextInt();
            if (num == data) {
                System.out.println("恭喜你猜对了 !");
                System.out.println("您猜的次数为：" + i);
            } else if (num > data) {
                System.out.println("太大了，再小点 !");
                System.out.println("您猜的次数为：" + i);
            } else if (num < data) {
                System.out.println("太小了，再大点 !");
                System.out.println("您猜的次数为：" + i);
            }
        }
        System.out.println("你太笨了，下次再来吧 !");
        System.out.println("正确答案是 ：" + data);
        System.exit(0);//退出程序
    }
}
